home *** CD-ROM | disk | FTP | other *** search
/ Aminet 6 / Aminet 6 - June 1995.iso / Aminet / gfx / 3d / irit50src.lha / irit5 / include / cagd_lib.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-14  |  40.9 KB  |  1,109 lines

  1. /******************************************************************************
  2. * Cagd_lib.h - header file for the CAGD library.                  *
  3. * This header is also the interface header to the world.              *
  4. *******************************************************************************
  5. * Written by Gershon Elber, Mar. 90.                          *
  6. ******************************************************************************/
  7.  
  8. #ifndef CAGD_LIB_H
  9. #define CAGD_LIB_H
  10.  
  11. #include <stdio.h>
  12. #include "irit_sm.h"
  13. #include "imalloc.h"
  14. #include "miscattr.h"
  15. #include "genmat.h"
  16.  
  17. typedef int CagdBType;
  18. typedef RealType CagdRType;
  19. typedef RealType CagdUVType[2];
  20. typedef PointType CagdPType;
  21. typedef VectorType CagdVType;
  22. typedef MatrixType CagdMType;
  23. typedef LineType CagdLType;
  24.  
  25. typedef enum {
  26.     CAGD_ERR_180_ARC = 1000,
  27.     CAGD_ERR_AFD_NO_SUPPORT,
  28.     CAGD_ERR_ALLOC_ERR,
  29.     CAGD_ERR_BSPLINE_NO_SUPPORT,
  30.     CAGD_ERR_BZR_CRV_EXPECT,
  31.     CAGD_ERR_BZR_SRF_EXPECT,
  32.     CAGD_ERR_BSP_CRV_EXPECT,
  33.     CAGD_ERR_BSP_SRF_EXPECT,
  34.     CAGD_ERR_CRV_FAIL_CMPT,
  35.     CAGD_ERR_CRVS_INCOMPATIBLE,
  36.     CAGD_ERR_CUBIC_EXPECTED,
  37.     CAGD_ERR_DEGEN_ALPHA,
  38.     CAGD_ERR_DIR_NOT_CONST_UV,
  39.     CAGD_ERR_DIR_NOT_VALID,
  40.     CAGD_ERR_INDEX_NOT_IN_MESH,
  41.     CAGD_ERR_KNOT_NOT_ORDERED,
  42.     CAGD_ERR_LIN_NO_SUPPORT,
  43.     CAGD_ERR_NO_CROSS_PROD,
  44.     CAGD_ERR_NOT_ENOUGH_MEM,
  45.     CAGD_ERR_NOT_IMPLEMENTED,
  46.     CAGD_ERR_NUM_KNOT_MISMATCH,
  47.     CAGD_ERR_OUT_OF_RANGE,
  48.     CAGD_ERR_PARSER_STACK_OV,
  49.     CAGD_ERR_POWER_NO_SUPPORT,
  50.     CAGD_ERR_PT_OR_LEN_MISMATCH,
  51.     CAGD_ERR_POLYNOMIAL_EXPECTED,
  52.     CAGD_ERR_RATIONAL_EXPECTED,
  53.     CAGD_ERR_SCALAR_EXPECTED,
  54.     CAGD_ERR_SRF_FAIL_CMPT,
  55.     CAGD_ERR_SRFS_INCOMPATIBLE,
  56.     CAGD_ERR_UNDEF_CRV,
  57.     CAGD_ERR_UNDEF_SRF,
  58.     CAGD_ERR_UNDEF_GEOM,
  59.     CAGD_ERR_UNSUPPORT_PT,
  60.     CAGD_ERR_T_NOT_IN_CRV,
  61.     CAGD_ERR_U_NOT_IN_SRF,
  62.     CAGD_ERR_V_NOT_IN_SRF,
  63.     CAGD_ERR_WRONG_DOMAIN,
  64.     CAGD_ERR_W_NOT_SAME,
  65.     CAGD_ERR_WRONG_CRV,
  66.     CAGD_ERR_WRONG_INDEX,
  67.     CAGD_ERR_WRONG_ORDER,
  68.     CAGD_ERR_WRONG_SRF,
  69.     CAGD_ERR_WRONG_PT_TYPE,
  70.     CAGD_ERR_CANNOT_COMP_VEC_FIELD,
  71.     CAGD_ERR_CANNOT_COMP_NORMAL,
  72.     CAGD_ERR_REPARAM_NOT_MONOTONE,
  73.     CAGD_ERR_RATIONAL_NO_SUPPORT,
  74.     CAGD_ERR_NO_SOLUTION,
  75.     CAGD_ERR_TOO_COMPLEX,
  76.     CAGD_ERR_REF_LESS_ORIG,
  77.     CAGD_ERR_ONLY_2D_OR_3D,
  78.     CAGD_ERR_DOMAIN_TOO_SMALL,
  79.     CAGD_ERR_PERIODIC_EXPECTED,
  80.     CAGD_ERR_PERIODIC_NO_SUPPORT,
  81.     CAGD_ERR_OPEN_EC_EXPECTED,
  82.  
  83.     CAGD_ERR_UNDEFINE_ERR
  84. } CagdFatalErrorType;
  85.  
  86. typedef enum {        /* Type of control point. The P-types are rationals. */
  87.     CAGD_PT_NONE = 0,
  88.     CAGD_PT_BASE = 1100,              /* Must be an even number. */
  89.     CAGD_PT_E1_TYPE = 1100,
  90.     CAGD_PT_P1_TYPE,
  91.     CAGD_PT_E2_TYPE,
  92.     CAGD_PT_P2_TYPE,
  93.     CAGD_PT_E3_TYPE,
  94.     CAGD_PT_P3_TYPE,
  95.     CAGD_PT_E4_TYPE,
  96.     CAGD_PT_P4_TYPE,
  97.     CAGD_PT_E5_TYPE,
  98.     CAGD_PT_P5_TYPE
  99. } CagdPointType;
  100.  
  101. #define CAGD_IS_RATIONAL_PT(PType)  (((int) ((PType) - CAGD_PT_BASE)) & 0x01)
  102. #define CAGD_NUM_OF_PT_COORD(PType) ((((int) ((PType) - CAGD_PT_BASE)) >> 1) + 1)
  103. #define CAGD_MAKE_PT_TYPE(IsRational, NumCoords) \
  104.                     ((CagdPointType) (CAGD_PT_BASE + \
  105.                          ((((IsRational) ? -1 : -2) \
  106.                                + ((NumCoords) << 1)))))
  107. #define CAGD_MAX_PT_SIZE        6    /* Rational P5 has 6 coords. */
  108. #define CAGD_MAX_PT_COORD        5               /* Without w. */
  109.  
  110. #define CAGD_IS_RATIONAL_CRV(Crv)    CAGD_IS_RATIONAL_PT((Crv) -> PType)
  111. #define CAGD_IS_RATIONAL_SRF(Srf)    CAGD_IS_RATIONAL_PT((Srf) -> PType)
  112.  
  113. /* Bezier curves may be evaluated using a predefined cache. The cache must   */
  114. /* be of size (FINENESS) which is power of 2 up to the maximum order below.  */
  115. /* See CrvBzrSetCache routine below.                         */
  116. #define CAGD_MAX_BEZIER_CACHE_ORDER    10
  117. #define CAGD_MAX_BEZIER_CACHE_FINENESS    1024
  118.  
  119. /* If a curve or a surface is periodic, their control polygon/mesh should    */
  120. /* warp up. Length does hold the real allocated length but the virtual       */
  121. /* periodic length is a little larger. Note allocated KV's are larger.       */
  122. #define CAGD_CRV_PT_LST_LEN(Crv) ((Crv) -> Length + \
  123.                   ((Crv) -> Periodic ? (Crv) -> Order - 1 : 0))
  124. #define CAGD_SRF_UPT_LST_LEN(Srf)    ((Srf) -> ULength + \
  125.                      ((Srf) -> UPeriodic ? \
  126.                           (Srf) -> UOrder - 1 : 0))
  127. #define CAGD_SRF_VPT_LST_LEN(Srf)    ((Srf) -> VLength + \
  128.                      ((Srf) -> VPeriodic ? \
  129.                           (Srf) -> VOrder - 1 : 0))
  130. #define CAGD_IS_PERIODIC_CRV(Crv)    ((Crv) -> Periodic)
  131. #define CAGD_IS_UPERIODIC_SRF(Srf)    ((Srf) -> UPeriodic)
  132. #define CAGD_IS_VPERIODIC_SRF(Srf)    ((Srf) -> VPeriodic)
  133. #define CAGD_IS_PERIODIC_SRF(Srf)    (CAGD_IS_UPERIODIC_SRF(Srf) || \
  134.                      CAGD_IS_VPERIODIC_SRF(Srf))
  135.  
  136.  
  137. #define CAGD_RESET_BBOX(BBox) { \
  138.     BBox -> Min[0] = BBox -> Min[1] = BBox -> Min[2] = INFINITY; \
  139.     BBox -> Max[0] = BBox -> Max[1] = BBox -> Max[2] = -INFINITY; }
  140.  
  141. typedef enum {
  142.     CAGD_UNDEF_TYPE = 1200,
  143.     CAGD_CBEZIER_TYPE,
  144.     CAGD_CBSPLINE_TYPE,
  145.     CAGD_CPOWER_TYPE,
  146.     CAGD_SBEZIER_TYPE,
  147.     CAGD_SBSPLINE_TYPE,
  148.     CAGD_SPOWER_TYPE
  149. } CagdGeomType;
  150.  
  151. typedef enum {
  152.     CAGD_NO_DIR = 1300,
  153.     CAGD_CONST_U_DIR,
  154.     CAGD_CONST_V_DIR
  155. } CagdSrfDirType;
  156. #define CAGD_OTHER_DIR(Dir) ((Dir) == CAGD_CONST_U_DIR ? CAGD_CONST_V_DIR \
  157.                                : CAGD_CONST_U_DIR)
  158.  
  159. typedef enum {
  160.     CAGD_REG_POLY_PER_LIN = 1400,
  161.     CAGD_ONE_POLY_PER_LIN,
  162.     CAGD_ONE_POLY_PER_COLIN
  163. } CagdLin2PolyType;
  164.  
  165. typedef enum {
  166.     CAGD_UNIFORM_PARAM = 1500,
  167.     CAGD_CENTRIPETAL_PARAM,
  168.     CAGD_CHORD_LEN_PARAM
  169. } CagdParametrizationType;
  170.  
  171. typedef struct CagdGenericStruct {
  172.     struct CagdGenericStruct *Pnext;
  173.     struct IPAttributeStruct *Attr;
  174. } CagdGenericStruct;
  175.  
  176. typedef struct CagdUVStruct {
  177.     struct CagdUVStruct *Pnext;
  178.     struct IPAttributeStruct *Attr;
  179.     CagdUVType UV;
  180. } CagdUVStruct;
  181.  
  182. typedef struct CagdPtStruct {
  183.     struct CagdPtStruct *Pnext;
  184.     struct IPAttributeStruct *Attr;
  185.     CagdPType Pt;
  186. } CagdPtStruct;
  187.  
  188. typedef struct CagdCtlPtStruct {
  189.     struct CagdCtlPtStruct *Pnext;
  190.     struct IPAttributeStruct *Attr;
  191.     CagdPointType PtType;
  192.     CagdRType Coords[CAGD_MAX_PT_SIZE];
  193. } CagdCtlPtStruct;
  194.  
  195. typedef struct CagdVecStruct {
  196.     struct CagdVecStruct *Pnext;
  197.     struct IPAttributeStruct *Attr;
  198.     CagdVType Vec;
  199. } CagdVecStruct;
  200.  
  201. typedef struct CagdPlaneStruct {
  202.     struct CagdPlaneStruct *Pnext;
  203.     struct IPAttributeStruct *Attr;
  204.     CagdRType Plane[4];
  205. } CagdPlaneStruct;
  206.  
  207. typedef struct CagdBBoxStruct {
  208.     struct CagdBBoxStruct *Pnext;
  209.     struct IPAttributeStruct *Attr;
  210.     CagdPType Min;
  211.     CagdPType Max;
  212. } CagdBBoxStruct;
  213.  
  214. typedef struct CagdCrvStruct {
  215.     struct CagdCrvStruct *Pnext;
  216.     struct IPAttributeStruct *Attr;
  217.     CagdGeomType GType;
  218.     CagdPointType PType;
  219.     int Length;            /* Number of control points (== order in Bezier). */
  220.     int Order;        /* Order of curve (only for Bspline, ignored in Bezier). */
  221.     CagdBType Periodic;               /* Valid only for Bspline curves. */
  222.     CagdRType *Points[CAGD_MAX_PT_SIZE];     /* Pointer on each axis vector. */
  223.     CagdRType *KnotVector;
  224. } CagdCrvStruct;
  225.  
  226. typedef struct CagdSrfStruct {
  227.     struct CagdSrfStruct *Pnext;
  228.     struct IPAttributeStruct *Attr;
  229.     CagdGeomType GType;
  230.     CagdPointType PType;
  231.     int ULength, VLength;     /* Mesh size in the tensor product surface. */
  232.     int UOrder, VOrder;   /* Order in tensor product surface (Bspline only). */
  233.     CagdBType UPeriodic, VPeriodic;      /* Valid only for Bspline surfaces. */
  234.     CagdRType *Points[CAGD_MAX_PT_SIZE];     /* Pointer on each axis vector. */
  235.     CagdRType *UKnotVector, *VKnotVector;
  236. } CagdSrfStruct;
  237.  
  238. typedef struct CagdPolygonStruct {
  239.     struct CagdPolygonStruct *Pnext;
  240.     struct IPAttributeStruct *Attr;
  241.     struct {
  242.     CagdPType Pt;                  /* Polygon is always triangle. */
  243.     CagdVType Nrml;
  244.     CagdUVType UV;
  245.     } Polygon[3];
  246. } CagdPolygonStruct;
  247.  
  248. typedef struct {
  249.     CagdPType Pt;
  250. } CagdPolylnStruct;
  251.  
  252. typedef struct CagdPolylineStruct {
  253.     struct CagdPolylineStruct *Pnext;
  254.     struct IPAttributeStruct *Attr;
  255.     CagdPolylnStruct *Polyline; /* Polyline length is defined using Length. */
  256.     int Length;
  257. } CagdPolylineStruct;
  258.  
  259. typedef struct {
  260.     int Order, Length, RefLength;     /* The dimensions of the alpha matrix. */
  261.     CagdRType *Matrix;
  262.     CagdRType **Rows;             /* A column of pointers to Matrix rows. */
  263.     int *ColIndex;     /* A row of indices of first non zero value in col. */
  264.     int *ColLength;          /* A row of lengths of non zero values in col. */
  265. } BspKnotAlphaCoeffType;
  266.  
  267. typedef void (*CagdPrintfFuncType)(char *Line);
  268. typedef CagdCrvStruct *(*CagdCrvFuncType)(CagdCrvStruct *Crv, CagdRType R);
  269.  
  270. #define CAGD_IS_BEZIER_CRV(Crv)        (Crv -> GType == CAGD_CBEZIER_TYPE)
  271. #define CAGD_IS_BEZIER_SRF(Srf)        (Srf -> GType == CAGD_SBEZIER_TYPE)
  272. #define CAGD_IS_BSPLINE_CRV(Crv)    (Crv -> GType == CAGD_CBSPLINE_TYPE)
  273. #define CAGD_IS_BSPLINE_SRF(Srf)    (Srf -> GType == CAGD_SBSPLINE_TYPE)
  274. #define CAGD_IS_POWER_CRV(Crv)        (Crv -> GType == CAGD_CPOWER_TYPE)
  275. #define CAGD_IS_POWER_SRF(Srf)        (Srf -> GType == CAGD_SPOWER_TYPE)
  276.  
  277. /******************************************************************************
  278. *        U -->                The mesh is ordered raw after raw *
  279. *       +-----------------------+    or the increments along U are 1 while *
  280. *   V | |P0                 Pi-1|    the increment along V is full raw.    *
  281. *     v    |Pi                P2i-1|        To encapsulate it, NEXTU/V are    *
  282. *    |            |    defined below.                  *
  283. *    |Pn-i            Pn-1|                          *
  284. *    +-----------------------+                          *
  285. ******************************************************************************/
  286. #define CAGD_NEXT_U(Srf)    (1)
  287. #define CAGD_NEXT_V(Srf)    (Srf -> ULength)
  288. #define CAGD_MESH_UV(Srf, i, j)    ((i) + (Srf -> ULength) * (j))
  289.  
  290.  
  291.  
  292. #define CAGD_GEN_COPY(Dst, Src, Size) memcpy((char *) (Dst), (char *) (Src), \
  293.                          Size)
  294.  
  295. #define CAGD_GEN_COPY_STEP(Dst, Src, Size, DstStep, SrcStep, Type) \
  296.             { \
  297.                 int ii; \
  298.                 Type *DstType = (Type *) Dst, \
  299.                  *SrcType = (Type *) Src; \
  300.  \
  301.                 for (ii = 0; ii < Size; ii++) { \
  302.                 *DstType = *SrcType; \
  303.                 DstType += DstStep; \
  304.                 SrcType += SrcStep; \
  305.                 } \
  306.             }
  307.  
  308. /******************************************************************************
  309. * Some points/ectors simplifying operators.                      *
  310. ******************************************************************************/
  311. #define    CAGD_COPY_POINT(DstPt, SrcPt)    { (DstPt) = (SrcPt); }
  312. #define    CAGD_ADD_POINT(DstPt, SrcPt)    { (DstPt).Pt[0] += (SrcPt).Pt[0]; \
  313.                       (DstPt).Pt[1] += (SrcPt).Pt[1]; \
  314.                       (DstPt).Pt[2] += (SrcPt).Pt[2]; }
  315. #define    CAGD_SUB_POINT(DstPt, SrcPt)    { (DstPt).Pt[0] -= (SrcPt).Pt[0]; \
  316.                       (DstPt).Pt[1] -= (SrcPt).Pt[1]; \
  317.                       (DstPt).Pt[2] -= (SrcPt).Pt[2]; }
  318. #define    CAGD_MULT_POINT(DstPt, Scaler)  { (DstPt).Pt[0] *= (Scaler); \
  319.                       (DstPt).Pt[1] *= (Scaler); \
  320.                       (DstPt).Pt[2] *= (Scaler); }
  321.  
  322. #define    CAGD_COPY_VECTOR(DstVec, SrcVec) { (DstVec) = (SrcVec); }
  323. #define    CAGD_ADD_VECTOR(DstVec, SrcVec) { (DstVec).Vec[0] += (SrcVec).Vec[0]; \
  324.                       (DstVec).Vec[1] += (SrcVec).Vec[1]; \
  325.                       (DstVec).Vec[2] += (SrcVec).Vec[2]; }
  326. #define    CAGD_SUB_VECTOR(DstVec, SrcVec) { (DstVec).Vec[0] -= (SrcVec).Vec[0]; \
  327.                       (DstVec).Vec[1] -= (SrcVec).Vec[1]; \
  328.                       (DstVec).Vec[2] -= (SrcVec).Vec[2]; }
  329. #define    CAGD_MULT_VECTOR(DstVec, Scaler){ (DstVec).Vec[0] *= (Scaler); \
  330.                       (DstVec).Vec[1] *= (Scaler); \
  331.                       (DstVec).Vec[2] *= (Scaler); }
  332. #define    CAGD_DIV_VECTOR(DstVec, Scaler) { (DstVec).Vec[0] /= (Scaler); \
  333.                       (DstVec).Vec[1] /= (Scaler); \
  334.                       (DstVec).Vec[2] /= (Scaler); }
  335. #define CAGD_LEN_VECTOR(V)        sqrt(SQR((V).Vec[0]) + \
  336.                          SQR((V).Vec[1]) + \
  337.                          SQR((V).Vec[2]))
  338. #define CAGD_NORMALIZE_VECTOR(V)    { CagdRType __t = CAGD_LEN_VECTOR(V); \
  339.                       if (__t < PT_NORMALIZE_ZERO) { \
  340.                           fprintf(stderr, "Attempt to cagd normalize a zero length vector\n"); \
  341.                       } \
  342.                       else { \
  343.                           CAGD_DIV_VECTOR((V), __t); \
  344.                       } \
  345.                         }
  346.  
  347.  
  348. #define    CAGD_COPY_UVVAL(DstUV, SrcUV) { (DstUV) = (SrcUV); }
  349.  
  350. /******************************************************************************
  351. * This macro is called when the library has detected an unrecoverable error.  *
  352. * Default action is to call CagdFatalError, but you may want to reroute this  *
  353. * to invoke your handler and recover yourself (by long jump for example).     *
  354. ******************************************************************************/
  355. #define CAGD_FATAL_ERROR(Msg)    CagdFatalError(Msg)
  356.  
  357. /******************************************************************************
  358. * Macros to verify the validity of the parametric domain.              *
  359. ******************************************************************************/
  360. #ifdef DOUBLE
  361. #define CAGD_DOMAIN_EPSILON 1e-13
  362. #else
  363. #define CAGD_DOMAIN_EPSILON 1e-5
  364. #endif /* DOUBLE */
  365.  
  366. #define CAGD_DOMAIN_T_VERIFY(t, TMin, TMax) \
  367.     { \
  368.     if (t < TMin) \
  369.         t += CAGD_DOMAIN_EPSILON; \
  370.     if (t > TMax) \
  371.         t -= CAGD_DOMAIN_EPSILON; \
  372.     if (t < TMin || t > TMax) \
  373.         CAGD_FATAL_ERROR(CAGD_ERR_T_NOT_IN_CRV); \
  374.     }
  375.  
  376. #define CAGD_DOMAIN_GET_AND_VERIFY_CRV(t, Crv, TMin, TMax) \
  377.     { \
  378.     CagdCrvDomain(Crv, &TMin, &TMax); \
  379.     CAGD_DOMAIN_T_VERIFY(t, TMin, TMax); \
  380.     }
  381.  
  382. #define CAGD_DOMAIN_GET_AND_VERIFY_SRF(u, v, Srf, UMin, UMax, VMin, VMax) \
  383.     { \
  384.     CagdSrfDomain(Srf, &UMin, &UMax, &VMin, &VMax); \
  385.     CAGD_DOMAIN_T_VERIFY(u, UMin, UMax); \
  386.     CAGD_DOMAIN_T_VERIFY(v, VMin, VMax); \
  387.     }
  388.  
  389. /******************************************************************************
  390. * A fast macro to blend the original control polygon with the Alpha matrix.   *
  391. ******************************************************************************/
  392. #define CAGD_ALPHA_BLEND( A, Index, OrigPts, OrigLen, Pt ) \
  393.     { \
  394.     if (A -> ColLength[Index] == 1) \
  395.         *Pt = OrigPts[A -> ColIndex[Index] % OrigLen]; \
  396.     else { \
  397.         int Tmp; \
  398.  \
  399.         *Pt = 0.0; \
  400.         for (Tmp = A -> ColLength[Index] - 1; Tmp >= 0; Tmp--) { \
  401.         int Idx = A -> ColIndex[Index] + Tmp; \
  402.  \
  403.         *Pt += OrigPts[Idx % OrigLen] * A -> Rows[Idx][Index]; \
  404.         } \
  405.     } \
  406.     }
  407.  
  408. /* Same as CAGD_ALPHA_BLEND but Allow step for OrigPts. */
  409. #define CAGD_ALPHA_BLEND_STEP( A, Index, OrigPts, OrigLen, Pt, OrigPtsStep ) \
  410.     { \
  411.     if (A -> ColLength[Index] == 1) \
  412.         *Pt = OrigPts[A -> ColIndex[Index] * OrigPtsStep]; \
  413.     else { \
  414.         int Tmp; \
  415.  \
  416.         *Pt = 0.0; \
  417.         for (Tmp = A -> ColLength[Index] - 1; Tmp >= 0; Tmp--) { \
  418.         int Idx = A -> ColIndex[Index] + Tmp; \
  419.  \
  420.         *Pt += OrigPts[Idx * OrigPtsStep] * A -> Rows[Idx][Index]; \
  421.         } \
  422.     } \
  423.     }
  424.  
  425. /******************************************************************************
  426. * There are some circular links to symb_lib and we include symb.lib.h         *
  427. * to resolve that. This may cause some problems in linkage time.              *
  428. * These are the known circularities:                              *
  429. * Bsp/BzrCrvMult, Bsp/BzrSrfMult, Bsp/BzrCrvDeriveRational.                  *
  430. ******************************************************************************/
  431. #include "symb_lib.h"
  432.  
  433. /******************************************************************************
  434. * Routines prototypes. Routines are prefixed as follows:              *
  435. * Cagd    - General routines such as dynamic memory handlers etc.          *
  436. * BzrCrv  - Bezier curves routines.                          *
  437. * BzrSrf  - Bezier surface routines.                          *
  438. * BspKnot - Bspline knot vector routines.                      *
  439. * BspCrv  - Bspline curves routines.                          *
  440. * BspSrf  - Bspline surface routines.                          *
  441. * Cnvrt   - Conversion routines such as Bezier to Power basis.              *
  442. ******************************************************************************/
  443.  
  444. #if defined(__cplusplus) || defined(c_plusplus)
  445. extern "C" {
  446. #endif
  447.  
  448. /******************************************************************************
  449. * General routines of the Cagd library:                          *
  450. ******************************************************************************/
  451.  
  452. CagdUVStruct *CagdUVNew(void);
  453. CagdPtStruct *CagdPtNew(void);
  454. CagdCtlPtStruct *CagdCtlPtNew(CagdPointType PtType);
  455. CagdVecStruct *CagdVecNew(void);
  456. CagdPlaneStruct *CagdPlaneNew(void);
  457. CagdBBoxStruct *CagdBBoxNew(void);
  458. CagdCrvStruct *CagdCrvNew(CagdGeomType GType, CagdPointType PType, int Length);
  459. CagdCrvStruct *CagdPeriodicCrvNew(CagdGeomType GType,
  460.                   CagdPointType PType,
  461.                   int Length,
  462.                   CagdBType Periodic);
  463. CagdSrfStruct *CagdSrfNew(CagdGeomType GType,
  464.               CagdPointType PType,
  465.               int ULength,
  466.               int VLength);
  467. CagdSrfStruct *CagdPeriodicSrfNew(CagdGeomType GType,
  468.                   CagdPointType PType,
  469.                   int ULength,
  470.                   int VLength,
  471.                   CagdBType UPeriodic,
  472.                   CagdBType VPeriodic);
  473. CagdPolygonStruct *CagdPolygonNew(void);
  474. CagdPolylineStruct *CagdPolylineNew(int Length);
  475.  
  476. CagdUVStruct *CagdUVArrayNew(int Size);
  477. CagdPtStruct *CagdPtArrayNew(int Size);
  478. CagdCtlPtStruct *CagdCtlPtArrayNew(CagdPointType PtType, int Size);
  479. CagdVecStruct *CagdVecArrayNew(int Size);
  480. CagdPlaneStruct *CagdPlaneArrayNew(int Size);
  481. CagdBBoxStruct *CagdBBoxArrayNew(int Size);
  482. CagdPolygonStruct *CagdPolygonArrayNew(int Size);
  483. CagdPolylineStruct *CagdPolylineArrayNew(int Length, int Size);
  484.  
  485. CagdCrvStruct *CagdCrvCopy(CagdCrvStruct *Crv);
  486. CagdSrfStruct *CagdSrfCopy(CagdSrfStruct *Srf);
  487. CagdUVStruct *CagdUVCopy(CagdUVStruct *UV);
  488. CagdPtStruct *CagdPtCopy(CagdPtStruct *Pt);
  489. CagdCtlPtStruct *CagdCtlPtCopy(CagdCtlPtStruct *CtlPt);
  490. CagdVecStruct *CagdVecCopy(CagdVecStruct *Vec);
  491. CagdPlaneStruct *CagdPlaneCopy(CagdPlaneStruct *Plane);
  492. CagdBBoxStruct *CagdBBoxCopy(CagdBBoxStruct *BBoc);
  493. CagdPolygonStruct *CagdPolygonCopy(CagdPolygonStruct *Poly);
  494. CagdPolylineStruct *CagdPolylineCopy(CagdPolylineStruct *Poly);
  495.  
  496. CagdCrvStruct *CagdCrvCopyList(CagdCrvStruct *CrvList);
  497. CagdSrfStruct *CagdSrfCopyList(CagdSrfStruct *SrfList);
  498. CagdUVStruct *CagdUVCopyList(CagdUVStruct *UVList);
  499. CagdPtStruct *CagdPtCopyList(CagdPtStruct *PtList);
  500. CagdCtlPtStruct *CagdCtlPtCopyList(CagdCtlPtStruct *CtlPtList);
  501. CagdVecStruct *CagdVecCopyList(CagdVecStruct *VecList);
  502. CagdPlaneStruct *CagdPlaneCopyList(CagdPlaneStruct *PlaneList);
  503. CagdBBoxStruct *CagdBBoxCopyList(CagdBBoxStruct *BBoxList);
  504. CagdPolylineStruct *CagdPolylineCopyList(CagdPolylineStruct *PolyList);
  505. CagdPolygonStruct *CagdPolygonCopyList(CagdPolygonStruct *PolyList);
  506.  
  507. void CagdCrvFree(CagdCrvStruct *Crv);
  508. void CagdCrvFreeList(CagdCrvStruct *CrvList);
  509. void CagdSrfFree(CagdSrfStruct *Srf);
  510. void CagdSrfFreeList(CagdSrfStruct *SrfList);
  511. void CagdUVFree(CagdUVStruct *UV);
  512. void CagdUVFreeList(CagdUVStruct *UVList);
  513. void CagdUVArrayFree(CagdUVStruct *UVArray, int Size);
  514. void CagdPtFree(CagdPtStruct *Pt);
  515. void CagdPtFreeList(CagdPtStruct *PtList);
  516. void CagdPtArrayFree(CagdPtStruct *PtArray, int Size);
  517. void CagdCtlPtFree(CagdCtlPtStruct *CtlPt);
  518. void CagdCtlPtFreeList(CagdCtlPtStruct *CtlPtList);
  519. void CagdCtlPtArrayFree(CagdCtlPtStruct *CtlPtArray, int Size);
  520. void CagdVecFree(CagdVecStruct *Vec);
  521. void CagdVecFreeList(CagdVecStruct *VecList);
  522. void CagdVecArrayFree(CagdVecStruct *VecArray, int Size);
  523. void CagdPlaneFree(CagdPlaneStruct *Plane);
  524. void CagdPlaneFreeList(CagdPlaneStruct *PlaneList);
  525. void CagdPlaneArrayFree(CagdPlaneStruct *PlaneArray, int Size);
  526. void CagdBBoxFree(CagdBBoxStruct *BBox);
  527. void CagdBBoxFreeList(CagdBBoxStruct *BBoxList);
  528. void CagdBBoxArrayFree(CagdBBoxStruct *BBoxArray, int Size);
  529. void CagdPolylineFree(CagdPolylineStruct *Poly);
  530. void CagdPolylineFreeList(CagdPolylineStruct *PolyList);
  531. void CagdPolylineArrayFree(CagdPolylineStruct *PolyArray, int Size);
  532. void CagdPolygonFree(CagdPolygonStruct *Poly);
  533. void CagdPolygonFreeList(CagdPolygonStruct *PolyList);
  534. void CagdPolygonArrayFree(CagdPolygonStruct *PolyArray, int Size);
  535.  
  536. int CagdListLength(VoidPtr CrvList);
  537. VoidPtr CagdListReverse(VoidPtr List);
  538. VoidPtr CagdListLast(VoidPtr List);
  539. void CagdCoerceToE2(CagdRType *E2Point,
  540.             CagdRType *Points[CAGD_MAX_PT_SIZE],
  541.             int Index,
  542.             CagdPointType PType);
  543. void CagdCoerceToE3(CagdRType *E3Point,
  544.             CagdRType *Points[CAGD_MAX_PT_SIZE],
  545.             int Index,
  546.             CagdPointType PType);
  547. void CagdCoerceToP2(CagdRType *P2Point,
  548.             CagdRType *Points[CAGD_MAX_PT_SIZE],
  549.             int Index,
  550.             CagdPointType PType);
  551. void CagdCoerceToP3(CagdRType *P3Point,
  552.             CagdRType *Points[CAGD_MAX_PT_SIZE],
  553.             int Index,
  554.             CagdPointType PType);
  555. void CagdCoercePointTo(CagdRType *NewPoint,
  556.                CagdPointType NewPType,
  557.                CagdRType *Points[CAGD_MAX_PT_SIZE],
  558.                int Index,
  559.                CagdPointType OldPType);
  560. void CagdCoercePointsTo(CagdRType *Points[],
  561.             int Len,
  562.             CagdPointType OldPType,
  563.             CagdPointType NewPType);
  564. CagdCrvStruct *CagdCoerceCrvTo(CagdCrvStruct *Crv, CagdPointType PType);
  565. CagdSrfStruct *CagdCoerceSrfTo(CagdSrfStruct *Srf, CagdPointType PType);
  566. CagdPointType CagdMergePointType(CagdPointType PType1, CagdPointType PType2);
  567. void CagdDbg(void *Obj);
  568. void CagdSetCagdFprintf(CagdPrintfFuncType Func);
  569. void CagdSetLinear2Poly(CagdLin2PolyType Lin2Poly);
  570. void CagdMergeBBox(CagdBBoxStruct *DestBBox, CagdBBoxStruct *SrcBBox);
  571. void CagdPointsBBox(CagdRType **Points, int Length, CagdBBoxStruct *BBox);
  572. CagdRType CagdIChooseK(int i, int k);
  573. void CagdTransform(CagdRType **Points,
  574.            int Len,
  575.            int MaxCoord,
  576.            CagdBType IsNotRational,
  577.            CagdRType *Translate,
  578.            CagdRType Scale);
  579. void CagdMatTransform(CagdRType **Points,
  580.               int Len,
  581.               int MaxCoord,
  582.               CagdBType IsNotRational,
  583.               CagdMType Mat);
  584.  
  585. /******************************************************************************
  586. * Matrix/Vector/Plane/Transformation routines:                      *
  587. ******************************************************************************/
  588. CagdRType CagdDistanceTwoCtlPts(CagdRType **Points,
  589.                 int Index1,
  590.                 int Index2,
  591.                 CagdPointType PType);
  592. CagdRType CagdFitPlaneThruCtlPts(CagdPlaneStruct *Plane,
  593.                  CagdPointType PType,
  594.                      CagdRType **Points,
  595.                      int Index1,
  596.                  int Index2,
  597.                  int Index3,
  598.                  int Index4);
  599. CagdRType CagdDistPtPlane(CagdPlaneStruct *Plane,
  600.               CagdRType **Points,
  601.               int Index,
  602.               int MaxDim);
  603.  
  604. void CagdCrvMatTransform(CagdCrvStruct *Crv, CagdMType Mat);
  605. void CagdSrfMatTransform(CagdSrfStruct *Srf, CagdMType Mat);
  606. void CagdCrvTransform(CagdCrvStruct *Crv,
  607.               CagdRType *Translate,
  608.               CagdRType Scale);
  609. void CagdSrfTransform(CagdSrfStruct *Srf,
  610.               CagdRType *Translate,
  611.               CagdRType Scale);
  612.  
  613. /******************************************************************************
  614. * Routines to handle curves generically.                      *
  615. ******************************************************************************/
  616. CagdRType *CagdCrvNodes(CagdCrvStruct *Crv);
  617. CagdRType CagdEstimateCrvColinearity(CagdCrvStruct *Crv);
  618. void CagdCrvDomain(CagdCrvStruct *Crv, CagdRType *TMin, CagdRType *TMax);
  619. CagdRType *CagdCrvEval(CagdCrvStruct *Crv, CagdRType t);
  620. CagdCrvStruct *CagdCrvDerive(CagdCrvStruct *Crv);
  621. CagdCrvStruct *CagdCrvIntegrate(CagdCrvStruct *Crv);
  622. CagdCrvStruct *CagdCrvSubdivAtParam(CagdCrvStruct *Crv, CagdRType t);
  623. CagdCrvStruct *CagdCrvRegionFromCrv(CagdCrvStruct *Crv,
  624.                     CagdRType t1,
  625.                     CagdRType t2);
  626. CagdCrvStruct *CagdCrvRefineAtParams(CagdCrvStruct *Crv,
  627.                      CagdBType Replace,
  628.                      CagdRType *t,
  629.                      int n);
  630. CagdVecStruct *CagdCrvTangent(CagdCrvStruct *Crv, CagdRType t);
  631. CagdVecStruct *CagdCrvBiNormal(CagdCrvStruct *Crv, CagdRType t);
  632. CagdVecStruct *CagdCrvNormal(CagdCrvStruct *Crv, CagdRType t);
  633. CagdCrvStruct *CagdCrvReverse(CagdCrvStruct *Crv);
  634. CagdCrvStruct *CagdCrvDegreeRaise(CagdCrvStruct *Crv);
  635. CagdCrvStruct *CagdCrvDegreeRaiseN(CagdCrvStruct *Crv, int NewOrder);
  636. CagdCrvStruct *CagdMergeCrvCrv(CagdCrvStruct *Crv1,
  637.                    CagdCrvStruct *Crv2,
  638.                    int InterpDiscont);
  639. CagdCrvStruct *CagdMergeCrvList(CagdCrvStruct *CrvList, int InterpDiscont);
  640. CagdCrvStruct *CagdMergeCrvPt(CagdCrvStruct *Crv, CagdPtStruct *Pt);
  641. CagdCrvStruct *CagdMergePtCrv(CagdPtStruct *Pt, CagdCrvStruct *Crv);
  642. CagdCrvStruct *CagdMergePtPt(CagdPtStruct *Pt1, CagdPtStruct *Pt2);
  643. CagdPolylineStruct *CagdCrv2CtrlPoly(CagdCrvStruct *Crv);
  644. CagdCrvStruct *CagdEditSingleCrvPt(CagdCrvStruct *Crv,
  645.                    CagdCtlPtStruct *CtlPt,
  646.                    int Index,
  647.                    CagdBType Write);
  648. CagdBType CagdMakeCrvsCompatible(CagdCrvStruct **Crv1,
  649.                  CagdCrvStruct **Crv2,
  650.                  CagdBType SameOrder,
  651.                  CagdBType SameKV);
  652. void CagdCrvBBox(CagdCrvStruct *Crv, CagdBBoxStruct *BBox);
  653. void CagdCrvListBBox(CagdCrvStruct *Crvs,
  654.              CagdBBoxStruct *BBox);
  655. void CagdCrvMinMax(CagdCrvStruct *Crv,
  656.            int Axis,
  657.            CagdRType *Min,
  658.            CagdRType *Max);
  659. int CagdCrvEvalToPolyline(CagdCrvStruct *Crv,
  660.               int FineNess,
  661.               CagdRType *Points[],
  662.               BspKnotAlphaCoeffType *A,
  663.               CagdBType OptiLin);
  664. void CagdCrvFirstMoments(CagdCrvStruct *Crv,
  665.              int n,
  666.              CagdPType Pt,
  667.              CagdVType Dir);
  668.  
  669. /******************************************************************************
  670. * Routines to handle surfaces generically.                      *
  671. ******************************************************************************/
  672. CagdRType *CagdSrfNodes(CagdSrfStruct *Srf, CagdSrfDirType Dir);
  673. CagdRType CagdEstimateSrfPlanarity(CagdSrfStruct *Srf);
  674. void CagdSrfDomain(CagdSrfStruct *Srf,
  675.            CagdRType *UMin,
  676.            CagdRType *UMax,
  677.            CagdRType *VMin,
  678.            CagdRType *VMax);
  679. CagdRType *CagdSrfEval(CagdSrfStruct *Srf, CagdRType u, CagdRType v);
  680. void CagdEvaluateSurfaceVecField(CagdVType Vec,
  681.                  CagdSrfStruct *VecFieldSrf,
  682.                  CagdRType U,
  683.                  CagdRType V);
  684. CagdSrfStruct *CagdSrfDerive(CagdSrfStruct *Srf, CagdSrfDirType Dir);
  685. CagdCrvStruct *CagdCrvFromSrf(CagdSrfStruct *Srf,
  686.                   CagdRType t,
  687.                   CagdSrfDirType Dir);
  688. CagdCrvStruct *CagdCrvFromMesh(CagdSrfStruct *Srf,
  689.                    int Index,
  690.                    CagdSrfDirType Dir);
  691. void CagdCrvToMesh(CagdCrvStruct *Crv,
  692.            int Index,
  693.            CagdSrfDirType Dir,
  694.            CagdSrfStruct *Srf);
  695. CagdSrfStruct *CagdSrfSubdivAtParam(CagdSrfStruct *Srf,
  696.                     CagdRType t,
  697.                     CagdSrfDirType Dir);
  698. CagdSrfStruct *CagdSrfRegionFromSrf(CagdSrfStruct *Srf,
  699.                     CagdRType t1,
  700.                     CagdRType t2,
  701.                     CagdSrfDirType Dir);
  702. CagdSrfStruct *CagdSrfRefineAtParams(CagdSrfStruct *Srf,
  703.                      CagdSrfDirType Dir,
  704.                      CagdBType Replace,
  705.                      CagdRType *t,
  706.                      int n);
  707. CagdVecStruct *CagdSrfTangent(CagdSrfStruct *Srf,
  708.                   CagdRType u,
  709.                   CagdRType v,
  710.                   CagdSrfDirType Dir);
  711. CagdVecStruct *CagdSrfNormal(CagdSrfStruct *Srf, CagdRType u, CagdRType v);
  712. CagdSrfStruct *CagdSrfDegreeRaise(CagdSrfStruct *Srf, CagdSrfDirType Dir);
  713. CagdSrfStruct *CagdSrfReverse(CagdSrfStruct *Srf);
  714. CagdSrfStruct *CagdSrfReverse2(CagdSrfStruct *Srf);
  715. CagdPolylineStruct *CagdSrf2CtrlMesh(CagdSrfStruct *Srf);
  716. CagdSrfStruct *CagdMergeSrfSrf(CagdSrfStruct *Srf1,
  717.                    CagdSrfStruct *Srf2,
  718.                    CagdSrfDirType Dir,
  719.                    CagdBType SameEdge,
  720.                    int InterpolateDiscont);
  721. CagdSrfStruct *CagdMergeSrfList(CagdSrfStruct *SrfList,
  722.                 CagdSrfDirType Dir,
  723.                 CagdBType SameEdge,
  724.                 int InterpolateDiscont);
  725. CagdSrfStruct *CagdExtrudeSrf(CagdCrvStruct *Crv, CagdVecStruct *Vec);
  726. CagdSrfStruct *CagdSurfaceRev(CagdCrvStruct *Crv);
  727. CagdSrfStruct *CagdSurfaceRevPolynomialApprox(CagdCrvStruct *Crv);
  728. CagdSrfStruct *CagdSweepSrf(CagdCrvStruct *CrossSection,
  729.                 CagdCrvStruct *Axis,
  730.                 CagdCrvStruct *ScalingCrv,
  731.                 CagdRType Scale,
  732.                 VoidPtr Frame,
  733.                 CagdBType FrameIsCrv);
  734. CagdCrvStruct *CagdSweepAxisRefine(CagdCrvStruct *Axis,
  735.                    CagdCrvStruct *ScalingCrv,
  736.                    int RefLevel);
  737. CagdSrfStruct *CagdBoolSumSrf(CagdCrvStruct *CrvLeft,
  738.                   CagdCrvStruct *CrvRight,
  739.                   CagdCrvStruct *CrvTop,
  740.                   CagdCrvStruct *CrvBottom);
  741. CagdSrfStruct *CagdOneBoolSumSrf(CagdCrvStruct *BndryCrv);
  742. CagdSrfStruct *CagdRuledSrf(CagdCrvStruct *Crv1,
  743.                 CagdCrvStruct *Crv2,
  744.                 int OtherOrder,
  745.                 int OtherLen);
  746. CagdSrfStruct *CagdBilinearSrf(CagdPtStruct *Pt00,
  747.                    CagdPtStruct *Pt01,
  748.                    CagdPtStruct *Pt10,
  749.                    CagdPtStruct *Pt11);
  750. CagdSrfStruct *CagdPromoteCrvToSrf(CagdCrvStruct *Crv, CagdSrfDirType Dir);
  751. CagdSrfStruct *CagdSrfFromCrvs(CagdCrvStruct *CrvList, int OtherOrder);
  752. CagdBType CagdMakeSrfsCompatible(CagdSrfStruct **Srf1,
  753.                  CagdSrfStruct **Srf2,
  754.                  CagdBType SameUOrder,
  755.                  CagdBType SameVOrder,
  756.                  CagdBType SameUKV,
  757.                  CagdBType SameVKV);
  758. CagdSrfStruct *CagdEditSingleSrfPt(CagdSrfStruct *Srf,
  759.                    CagdCtlPtStruct *CtlPt,
  760.                    int UIndex,
  761.                    int VIndex,
  762.                    CagdBType Write);
  763. void CagdSrfBBox(CagdSrfStruct *Srf, CagdBBoxStruct *BBox);
  764. void CagdSrfListBBox(CagdSrfStruct *Srfs, CagdBBoxStruct *BBox);
  765. void CagdSrfMinMax(CagdSrfStruct *Srf,
  766.            int Axis,
  767.            CagdRType *Min,
  768.            CagdRType *Max);
  769.  
  770. /******************************************************************************
  771. * Routines to handle Bezier curves.                          *
  772. ******************************************************************************/
  773. CagdCrvStruct *BzrCrvNew(int Length, CagdPointType PType);
  774. CagdRType BzrCrvEvalVecAtParam(CagdRType *Vec,
  775.                    int VecInc,
  776.                    int Order,
  777.                    CagdRType t);
  778. CagdRType *BzrCrvEvalAtParam(CagdCrvStruct *Crv, CagdRType t);
  779. void BzrCrvSetCache(int FineNess, CagdBType EnableCache);
  780. void BzrCrvEvalToPolyline(CagdCrvStruct *Crv,
  781.               int FineNess,
  782.               CagdRType *Points[]);
  783. CagdCrvStruct *BzrCrvCreateArc(CagdPtStruct *Start,
  784.                    CagdPtStruct *Center,
  785.                    CagdPtStruct *End);
  786. CagdCrvStruct *BzrCrvSubdivAtParam(CagdCrvStruct *Crv, CagdRType t);
  787. CagdCrvStruct *BzrCrvDegreeRaise(CagdCrvStruct *Crv);
  788. CagdCrvStruct *BzrCrvDegreeRaiseN(CagdCrvStruct *Crv, int NewOrder);
  789. CagdCrvStruct *BzrCrvDerive(CagdCrvStruct *Crv);
  790. CagdCrvStruct *BzrCrvIntegrate(CagdCrvStruct *Crv);
  791. CagdVecStruct *BzrCrvTangent(CagdCrvStruct *Crv, CagdRType t);
  792. CagdVecStruct *BzrCrvBiNormal(CagdCrvStruct *Crv, CagdRType t);
  793. CagdVecStruct *BzrCrvNormal(CagdCrvStruct *Crv, CagdRType t);
  794. CagdCrvStruct *BzrCrvInterpolate(int Size,
  795.                  CagdRType *XVec,
  796.                  CagdRType *YVec,
  797.                  CagdRType *ZVec);
  798. CagdPolylineStruct *BzrCrv2Polyline(CagdCrvStruct *Crv, int SamplesPerCurve);
  799.  
  800. /******************************************************************************
  801. * Routines to handle Bezier surfaces.                          *
  802. ******************************************************************************/
  803. CagdSrfStruct *BzrSrfNew(int ULength, int VLength, CagdPointType PType);
  804. CagdRType *BzrSrfEvalAtParam(CagdSrfStruct *Srf, CagdRType u, CagdRType v);
  805. CagdCrvStruct *BzrSrfCrvFromSrf(CagdSrfStruct *Srf,
  806.                 CagdRType t,
  807.                 CagdSrfDirType Dir);
  808. CagdCrvStruct *BzrSrfCrvFromMesh(CagdSrfStruct *Srf,
  809.                  int Index,
  810.                  CagdSrfDirType Dir);
  811. CagdSrfStruct *BzrSrfSubdivAtParam(CagdSrfStruct *Srf,
  812.                    CagdRType t,
  813.                    CagdSrfDirType Dir);
  814. CagdSrfStruct *BzrSrfDegreeRaise(CagdSrfStruct *Srf, CagdSrfDirType Dir);
  815. CagdSrfStruct *BzrSrfDerive(CagdSrfStruct *Srf, CagdSrfDirType Dir);
  816. CagdVecStruct *BzrSrfTangent(CagdSrfStruct *Srf,
  817.                  CagdRType u,
  818.                  CagdRType v,
  819.                  CagdSrfDirType Dir);
  820. CagdVecStruct *BzrSrfNormal(CagdSrfStruct *Srf, CagdRType u, CagdRType v);
  821. CagdPolygonStruct *BzrSrf2Polygons(CagdSrfStruct *Srf,
  822.                    int FineNess,
  823.                    CagdBType ComputeNormals,
  824.                    CagdBType FourPerFlat,
  825.                    CagdBType ComputeUV);
  826. CagdPolylineStruct *BzrSrf2Polylines(CagdSrfStruct *Srf,
  827.                      int NumOfIsocurves[2],
  828.                      int SamplesPerCurve);
  829. CagdCrvStruct *BzrSrf2Curves(CagdSrfStruct *Srf, int NumOfIsocurves[2]);
  830.  
  831. /******************************************************************************
  832. * Routines to handle Bspline knot vectors.                      *
  833. ******************************************************************************/
  834. CagdBType BspCrvHasBezierKV(CagdCrvStruct *Crv);
  835. CagdBType BspSrfHasBezierKVs(CagdSrfStruct *Srf);
  836. CagdBType BspKnotHasBezierKV(CagdRType *KnotVector, int Len, int Order);
  837. CagdBType BspCrvHasOpenEC(CagdCrvStruct *Crv);
  838. CagdBType BspSrfHasOpenEC(CagdSrfStruct *Srf);
  839. CagdBType BspSrfHasOpenECDir(CagdSrfStruct *Srf, CagdSrfDirType Dir);
  840. CagdBType BspKnotHasOpenEC(CagdRType *KnotVector, int Len, int Order);
  841. CagdBType BspKnotParamInDomain(CagdRType *KnotVector,
  842.                    int Len,
  843.                    int Order,
  844.                    CagdBType Periodic,
  845.                    CagdRType t);
  846. int BspKnotLastIndexLE(CagdRType *KnotVector, int Len, CagdRType t);
  847. int BspKnotLastIndexL(CagdRType *KnotVector, int Len, CagdRType t);
  848. int BspKnotFirstIndexG(CagdRType *KnotVector, int Len, CagdRType t);
  849. CagdRType *BspKnotUniformPeriodic(int Len, int Order, CagdRType *KnotVector);
  850. CagdRType *BspKnotUniformFloat(int Len, int Order, CagdRType *KnotVector);
  851. CagdRType *BspKnotUniformOpen(int Len, int Order, CagdRType *KnotVector);
  852. CagdRType *BspKnotSubtrTwo(CagdRType *KnotVector1,
  853.                int Len1,
  854.                CagdRType *KnotVector2,
  855.                int Len2,
  856.                int *NewLen);
  857. CagdRType *BspKnotMergeTwo(CagdRType *KnotVector1,
  858.                int Len1,
  859.                CagdRType *KnotVector2,
  860.                int Len2,
  861.                int Mult,
  862.                int *NewLen);
  863. CagdRType *BspKnotContinuityMergeTwo(CagdRType *KnotVector1,
  864.                      int Len1,
  865.                      int Order1,
  866.                      CagdRType *KnotVector2,
  867.                      int Len2,
  868.                      int Order2,
  869.                      int ResOrder,
  870.                      int *NewLen);
  871. CagdRType *BspKnotAverage(CagdRType *KnotVector, int Len, int Ave);
  872. CagdRType *BspKnotNodes(CagdRType *KnotVector, int Len, int Order);
  873. CagdRType BspCrvMaxCoefParam(CagdCrvStruct *Crv, int Axis, CagdRType *MaxVal);
  874. CagdRType *BspSrfMaxCoefParam(CagdSrfStruct *Srf, int Axis, CagdRType *MaxVal);
  875. CagdRType *BspKnotPrepEquallySpaced(int n, CagdRType Tmin, CagdRType Tmax);
  876. CagdRType *BspKnotReverse(CagdRType *KnotVector, int Len);
  877. void BspKnotAffineTrans(CagdRType *KnotVector,
  878.             int Len,
  879.             CagdRType Translate,
  880.             CagdRType Scale);
  881. void BspKnotAffineTrans2(CagdRType *KnotVector,
  882.              int Len,
  883.              CagdRType MinVal,
  884.              CagdRType MaxVal);
  885. CagdRType *BspKnotCopy(CagdRType *KnotVector, int Len);
  886. BspKnotAlphaCoeffType *BspKnotEvalAlphaCoef(int k,
  887.                         CagdRType *KVT,
  888.                         int LengthKVT,
  889.                         CagdRType *KVt,
  890.                         int LengthKVt);
  891. BspKnotAlphaCoeffType *BspKnotEvalAlphaCoefMerge(int k,
  892.                          CagdRType *KVT,
  893.                          int LengthKVT,
  894.                          CagdRType *NewKV,
  895.                          int LengthNewKV);
  896. void BspKnotFreeAlphaCoef(BspKnotAlphaCoeffType *A);
  897. CagdRType *BspKnotInsertOne(CagdRType *KnotVector,
  898.                 int Order,
  899.                 int Len,
  900.                 CagdRType t);
  901. CagdRType *BspKnotInsertMult(CagdRType *KnotVector,
  902.                  int Order,
  903.                  int *Len,
  904.                  CagdRType t,
  905.                  int Mult);
  906. int BspKnotFindMult(CagdRType *KnotVector, int Order, int Len, CagdRType t);
  907. CagdBType BspKnotC1Discont(CagdRType *KnotVector,
  908.                int Order,
  909.                int Length,
  910.                CagdRType *t);
  911. CagdRType *BspKnotAllC1Discont(CagdRType *KnotVector,
  912.                    int Order,
  913.                    int Length,
  914.                    int *n);
  915. CagdRType *BspKnotParamValues(CagdRType PMin,
  916.                   CagdRType PMax,
  917.                   int NumSamples,
  918.                   CagdRType *C1Disconts,
  919.                   int NumC1Disconts);
  920. void BspKnotMakeRobustKV(CagdRType *KV, int Len);
  921.  
  922. /******************************************************************************
  923. * Routines to handle Bspline curves.                          *
  924. ******************************************************************************/
  925. CagdCrvStruct *BspCrvNew(int Length, int Order, CagdPointType PType);
  926. CagdCrvStruct *BspPeriodicCrvNew(int Length,
  927.                  int Order,
  928.                  CagdBType Periodic,
  929.                  CagdPointType PType);
  930. void BspCrvDomain(CagdCrvStruct *Crv, CagdRType *TMin, CagdRType *TMax);
  931.  
  932. CagdRType *BspCrvCoxDeBoorBasis(CagdRType *KnotVector,
  933.                 int Order,
  934.                 int Len,
  935.                 CagdRType t,
  936.                 int *IndexFirst);
  937. CagdRType *BspCrvEvalCoxDeBoor(CagdCrvStruct *Crv, CagdRType t);
  938. CagdRType BspCrvEvalVecAtParam(CagdRType *Vec,
  939.                    int VecInc,
  940.                    CagdRType *KnotVector,
  941.                    int Order,
  942.                    int Len,
  943.                    CagdBType Periodic,
  944.                    CagdRType t);
  945. CagdRType *BspCrvEvalAtParam(CagdCrvStruct *Crv, CagdRType t);
  946. CagdCrvStruct *BspCrvCreateCircle(CagdPtStruct *Center, CagdRType Radius);
  947. CagdCrvStruct *BspCrvCreateUnitCircle(void);
  948. CagdCrvStruct *BspCrvCreatePCircle(CagdPtStruct *Center, CagdRType Radius);
  949. CagdCrvStruct *BspCrvCreateUnitPCircle(void);
  950. CagdCrvStruct *BspCrvKnotInsert(CagdCrvStruct *Crv, CagdRType t);
  951. CagdCrvStruct *BspCrvKnotInsertNSame(CagdCrvStruct *Crv, CagdRType t, int n);
  952. CagdCrvStruct *BspCrvKnotInsertNDiff(CagdCrvStruct *Crv,
  953.                      CagdBType Replace,
  954.                      CagdRType *t,
  955.                      int n);
  956. CagdCrvStruct *BspCrvSubdivAtParam(CagdCrvStruct *Crv, CagdRType t);
  957. CagdCrvStruct *BspCrvOpenEnd(CagdCrvStruct *Crv);
  958. CagdCrvStruct *BspCrvDegreeRaise(CagdCrvStruct *Crv);
  959. CagdCrvStruct *BspCrvDegreeRaiseN(CagdCrvStruct *Crv, int NewOrder);
  960. CagdCrvStruct *BspCrvDerive(CagdCrvStruct *Crv);
  961. CagdCrvStruct *BspCrvIntegrate(CagdCrvStruct *Crv);
  962. CagdVecStruct *BspCrvTangent(CagdCrvStruct *Crv, CagdRType t);
  963. CagdVecStruct *BspCrvBiNormal(CagdCrvStruct *Crv, CagdRType t);
  964. CagdVecStruct *BspCrvNormal(CagdCrvStruct *Crv, CagdRType t);
  965. CagdPolylineStruct *BspCrv2Polyline(CagdCrvStruct *Crv,
  966.                     int SamplesPerCurve,
  967.                     BspKnotAlphaCoeffType *A,
  968.                     CagdBType OptiLin);
  969. CagdCrvStruct *BspCrvInterpPts(CagdPtStruct *PtList,
  970.                    int Order,
  971.                    int CrvSize,
  972.                    CagdParametrizationType ParamType);
  973. CagdCrvStruct *BspCrvInterpolate(CagdCtlPtStruct *PtList,
  974.                  int NumPts,
  975.                  CagdRType *Params,
  976.                  CagdRType *KV,
  977.                  int Length,
  978.                  int Order,
  979.                  CagdBType Periodic);
  980. CagdRType BspCrvInterpPtsError(CagdCrvStruct *Crv,
  981.                    CagdPtStruct *PtList,
  982.                    CagdParametrizationType ParamType);
  983.  
  984. /******************************************************************************
  985. * Routines to handle Bspline surfaces.                          *
  986. ******************************************************************************/
  987. CagdSrfStruct *BspSrfNew(int ULength,
  988.              int VLength,
  989.              int UOrder,
  990.              int VOrder,
  991.              CagdPointType PType);
  992. CagdSrfStruct *BspPeriodicSrfNew(int ULength,
  993.                  int VLength,
  994.                  int UOrder,
  995.                  int VOrder,
  996.                  CagdBType UPeriodic,
  997.                  CagdBType VPeriodic,
  998.                  CagdPointType PType);
  999. void BspSrfDomain(CagdSrfStruct *Srf,
  1000.           CagdRType *UMin,
  1001.           CagdRType *UMax,
  1002.           CagdRType *VMin,
  1003.           CagdRType *VMax);
  1004. CagdRType *BspSrfEvalAtParam(CagdSrfStruct *Srf, CagdRType u, CagdRType v);
  1005. CagdCrvStruct *BspSrfCrvFromSrf(CagdSrfStruct *Srf,
  1006.                 CagdRType t,
  1007.                 CagdSrfDirType Dir);
  1008. CagdCrvStruct *BspSrfCrvFromMesh(CagdSrfStruct *Srf,
  1009.                  int Index,
  1010.                  CagdSrfDirType Dir);
  1011. CagdSrfStruct *BspSrfKnotInsert(CagdSrfStruct *Srf,
  1012.                 CagdSrfDirType Dir,
  1013.                 CagdRType t);
  1014. CagdSrfStruct *BspSrfKnotInsertNSame(CagdSrfStruct *Srf,
  1015.                      CagdSrfDirType Dir,
  1016.                      CagdRType t, int n);
  1017. CagdSrfStruct *BspSrfKnotInsertNDiff(CagdSrfStruct *Srf,
  1018.                      CagdSrfDirType Dir,
  1019.                      int Replace,
  1020.                      CagdRType *t, int n);
  1021. CagdSrfStruct *BspSrfSubdivAtParam(CagdSrfStruct *Srf,
  1022.                    CagdRType t,
  1023.                    CagdSrfDirType Dir);
  1024. CagdSrfStruct *BspSrfOpenEnd(CagdSrfStruct *Srf);
  1025. CagdSrfStruct *BspSrfDegreeRaise(CagdSrfStruct *Srf, CagdSrfDirType Dir);
  1026. CagdSrfStruct *BspSrfDerive(CagdSrfStruct *Srf, CagdSrfDirType Dir);
  1027. CagdVecStruct *BspSrfTangent(CagdSrfStruct *Srf,
  1028.                  CagdRType u,
  1029.                  CagdRType v,
  1030.                  CagdSrfDirType Dir);
  1031. CagdVecStruct *BspSrfNormal(CagdSrfStruct *Srf, CagdRType u, CagdRType v);
  1032. CagdVecStruct *BspSrfMeshNormals(CagdSrfStruct *Srf,
  1033.                  int UFineNess,
  1034.                  int VFineNess);
  1035. CagdPolygonStruct *BspSrf2Polygons(CagdSrfStruct *Srf,
  1036.                    int FineNess,
  1037.                    CagdBType ComputeNormals,
  1038.                    CagdBType FourPerFlat,
  1039.                    CagdBType ComputeUV);
  1040. CagdPolylineStruct *BspSrf2Polylines(CagdSrfStruct *Srf,
  1041.                      int NumOfIsocurves[2],
  1042.                      int SamplesPerCurve);
  1043. CagdCrvStruct *BspSrf2Curves(CagdSrfStruct *Srf, int NumOfIsocurves[2]);
  1044. CagdSrfStruct *BspSrfInterpPts(CagdPtStruct **PtList,
  1045.                    int UOrder,
  1046.                    int VOrder,
  1047.                    int SrfUSize,
  1048.                    int SrfVSize,
  1049.                    CagdParametrizationType ParamType);
  1050. CagdSrfStruct *BspSrfInterpolate(CagdCtlPtStruct *PtList,
  1051.                  int NumUPts,
  1052.                  int NumVPts,
  1053.                  CagdRType *UParams,
  1054.                  CagdRType *VParams,
  1055.                  CagdRType *UKV,
  1056.                  CagdRType *VKV,
  1057.                  int ULength,
  1058.                  int VLength,
  1059.                  int UOrder,
  1060.                  int VOrder);
  1061.  
  1062. /******************************************************************************
  1063. * Routines to handle basis function conversions.                  *
  1064. ******************************************************************************/
  1065. CagdCrvStruct *CnvrtPower2BezierCrv(CagdCrvStruct *Crv);
  1066. CagdCrvStruct *CnvrtBezier2PowerCrv(CagdCrvStruct *Crv);
  1067. CagdCrvStruct *CnvrtBspline2BezierCrv(CagdCrvStruct *Crv);
  1068. CagdCrvStruct *CnvrtBezier2BsplineCrv(CagdCrvStruct *Crv);
  1069.  
  1070. CagdSrfStruct *CnvrtPower2BezierSrf(CagdSrfStruct *Srf);
  1071. CagdSrfStruct *CnvrtBezier2PowerSrf(CagdSrfStruct *Srf);
  1072. CagdSrfStruct *CnvrtBezier2BsplineSrf(CagdSrfStruct *Srf);
  1073. CagdSrfStruct *CnvrtBspline2BezierSrf(CagdSrfStruct *Srf);
  1074.  
  1075. CagdCrvStruct *CnvrtPeriodic2FloatCrv(CagdCrvStruct *Crv);
  1076. CagdSrfStruct *CnvrtPeriodic2FloatSrf(CagdSrfStruct *Srf);
  1077. CagdCrvStruct *CnvrtFloat2OpenCrv(CagdCrvStruct *Crv);
  1078. CagdSrfStruct *CnvrtFloat2OpenSrf(CagdSrfStruct *Srf);
  1079.  
  1080. CagdCrvStruct *CnvrtPolyline2LinBsplineCrv(CagdPolylineStruct *Poly);
  1081.  
  1082. /******************************************************************************
  1083. * Routines to handle adaptive forward differencing basis functions.          *
  1084. ******************************************************************************/
  1085. void AfdCnvrtCubicBzrToAfd(CagdRType Coef[4]);
  1086. void AfdApplyLn(CagdRType Coef[4], int n);
  1087. void AfdApplyEStep(CagdRType Coef[4]);
  1088. void AfdComputePolyline(CagdRType Coef[4],
  1089.             CagdRType *Poly,
  1090.             int Log2Step,
  1091.             CagdBType NonAdaptive);
  1092. void AfdBzrCrvEvalToPolyline(CagdCrvStruct *Crv,
  1093.                  int FineNess,
  1094.                  CagdRType *Points[]);
  1095.  
  1096. /******************************************************************************
  1097. * Error handling.                                  *
  1098. ******************************************************************************/
  1099. void CagdFatalError(CagdFatalErrorType ErrID);
  1100. char *CagdDescribeError(CagdFatalErrorType ErrID);
  1101.  
  1102. #if defined(__cplusplus) || defined(c_plusplus)
  1103. }
  1104. #endif
  1105.  
  1106. extern int _CagdGlblLineCount;         /* Used to locate errors in input file. */
  1107.  
  1108. #endif /* CAGD_LIB_H */
  1109.